<?php
namespace Common\Behavior;
use Think\Behavior;
use Think\Auth;
class CtrlAuthBehavior extends Behavior {
    public function run(&$params)
    {
        $me = D('Common/User')->getMe();
        if($this->isAdministrator()){
            // 超级管理员 畅通无阻
            return true;
        }
        $authDao = new Auth();
        $name = __INFO__;
        if(C('URL_HTML_SUFFIX')) {
            $name = preg_replace('/\.(' . trim(C('URL_HTML_SUFFIX'), '.') . ')$/i', '', __INFO__);
        }
        if(!$authDao->check($name, $me['id'], array('exp', '<>""'))) {
            E('抱歉，您的权限不足!');
        }
    }

    public function isAdministrator() {
        $UserDao = D('Common/User');
        $me = $UserDao->getLocalSession();
        // 超级管理员 跳过所有验证
        if ($UserDao->isAdministrator($me['id'])) {
            return true;
        }
        return false;
    }
}